<template>
	<view>
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="在线分钟数:" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="friendactiveteam.onlinetime" />
				</uni-forms-item>
				<uni-forms-item label="看视频次数:" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="friendactiveteam.videocount" />
				</uni-forms-item>
				<uni-forms-item label="邀请人数:" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="friendactiveteam.friendcount" />
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
		
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="扩散得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.onlinetimeprofit" />
				</uni-forms-item>
				<uni-forms-item label="扩散得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.videocountprofit" />
				</uni-forms-item>
				<uni-forms-item label="扩散得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.friendcountprofit" />
				</uni-forms-item>
			</uni-forms>
		</view>
		
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="直推得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.onlinetimeprofit * 2" disabled=true style="border: none;"/>
				</uni-forms-item>
				<uni-forms-item label="直推得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.videocountprofit *2" disabled=true style="border: none;"/>
				</uni-forms-item>
				<uni-forms-item label="直推得钱:" name="title" labelWidth="80">
					<input class="uni-input-border" type="number" v-model="friendprofit.friendcountprofit *2" disabled=true style="border: none;"/>
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"friendactiveteam":{
					"onlinetime":0,
					videocount:0,
					friendcount:0
				},    
				"friendprofit":{
					"onlinetimeprofit":0,           // fen
					"videocountprofit":0,           // fen
					"friendcountprofit":0,           // fen
				},	
			}
		},
		methods: {
			getinfo(){
				var self = this
				this.isLoading = true
				this.$request('admin/loadconfig',{id:'friendactiveteam'}).then(res => {
					this.isLoading = false
					var json = res.config
					self.friendactiveteam = json
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
				
				this.$request('admin/loadconfig',{id:'friendprofit'}).then(res => {
					this.isLoading = false
					var json = res.config
					self.friendprofit = json
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			},
			save(){
				var self = this
				self.isLoading = true
				delete self.friendactiveteam._id;
				for(let key in self.friendactiveteam){
					if(key != '_id'){
						self.friendactiveteam[key] = Number(self.friendactiveteam[key])
					}
				}
				self.$request('admin/setconfig',{json:JSON.stringify({friendactiveteam:self.friendactiveteam})}).then(res => {
					self.isLoading = false
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
				
				
				
				delete self.friendprofit._id;
				for(let key in self.friendprofit){
					if(key != '_id'){
						self.friendprofit[key] = Number(self.friendprofit[key])
					}
				}
				self.$request('admin/setconfig',{json:JSON.stringify({friendprofit:self.friendprofit})}).then(res => {
					self.isLoading = false
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			}
		},
		mounted() {
			var self = this
			self.getinfo()
		}
	}
</script>

<style>

</style>
